<?php
/**
 * Created by PhpStorm.
 * User: xiaomeng
 * Date: 17-9-18
 * Time: 上午11:50
 */
namespace swf\socket;

use swf\common\Curl;

class OpenNum
{
    static private $list = [25,2,3,2,8,2,5,2,12,3,2,3,5,2,8,3,12,3,2,5,2,3,2,5,2,3,8,2,3,2,5,2];
    static public function run()
    {
            $res = self::getIndex();
            $data['open_num'] = self::$list[$res['index']];
            $data['open_deg'] = $res['index'] * 11.25;
            $data['open_type'] = $res['type'];
            $data['open_index'] = $res['index'];
            return $data;
    }

    static public function getIndex()
    {
        $url = "https://www.random.org/integers/?num=1&min=0&max=31&col=1&base=10&format=plain&rnd=new";
        $curl = new Curl();
        $res = $curl->get($url);
        if($res !== false)
        {
            $data['type'] = 1;
            $data['index'] = (int)trim($res);
        } else {
            $data['type'] = 2;
            $data['index'] = rand(0,31);
        }
        return $data;
    }
}